import { post, get } from '@/utils/request'

/**
 * 加载泵车数据
 */
export function loadCarData (data) {
	return post('/htnweapp/getVehicleList', Object.assign({
		pageNo: 0,
		pageSize: 20
	}, data))
}

/**
 * 加载公司下面的泵车数据 
 */
export function loadCompanyCarData (data) {
	return post('/htnweapp/findCompanyVehicles', data)
}

/**
 * 获取泵车数据
 */
export function getCompanyCarsByIds (ids) {
	return post('/htnweapp/findCompanyVehicles', {}).then(rs => {
		return (ids || []).map(v => {
			return (rs.avaliableVehicles || []).find(vv => vv.id === v)
		}).filter(v => !!v)
	})
}

/**
 * 创建泵车
 */
export function createCar (data) {
	return post('/htnweapp/addOutsideVehicleInfo', Object.assign({
		vehicleType: null,
		vehicleModel: null,
		leasingCompanyId: null,
		leasingCompanyName: null
	}, data))
}

/**
 * 批量创建泵车
 */
export function batchCreateCar (data) {
	return post('/htnweapp/addOutsideVehicleBatch', Object.assign({
		/**
		 * [{
			 leasingCompanyId: '',
			 leasingCompanyName: '',
			 vehicleModel: '',
			 vehicleType: ''
		 }]
		 */
		vehicles: []
	}, data))
}

/**
 * 更新泵车
 */
export function updateCar () {
	
}

/**
 * 删除泵车
 */
export function deleteCar () {
	
}

/**
 * 加载泵车类型型号数据
 */
export function loadCarModelTypeOptions () {
	return post('/htnweapp/findVehicleTypeAndModels')
}

/**
 * 更新泵车司机信息
 */
export function updateCarDriver (data) {
	return post('/htnweapp/changeVehicleDriver', Object.assign({
		id: null,
		/**
		 * [{
			 driverId: null
		 }]
		 */
		driverCountVOS: []
	}, data))
}

/**
 * 获取泵车明细
 */
export function getCarDetail (id) {
	return post('/htnweapp/findCompanyVehicles', {}).then(rs => {
		const car = (rs.avaliableVehicles || []).find(v => v.id === id)
		if (car) {
			return car
		} else {
			return Promise.reject(`未找到泵车${id}`)
		}
	}) 
}

/**
 * 创建自有车
 */
export function createSelfCar (data) {
	return post('/common/saveOrUpdateVehicle', Object.assign({
		vehiclePlate: null,
		carNum: null,
		vehicleType: null,
		vehicleModel: null
	}, data))
}

/**
 * 更新自有车
 */
export function updateSelfCar (data) {
	return post('/common/saveOrUpdateVehicle', Object.assign({
		id: null
	}, data))
}

/**
 * 删除自由车
 */
export function deleteSelfCar (id) {
	return get(`/common/deleteVehicleById?id=${id}`)
}

/**
 * 获取公司自有车辆数据
 */
export function loadSelfCarData () {
	return get('/common/getVehicleList')
}

export function loadSelfCarDataWithGps () {
    return get('/common/getVehicleListWithGps')
}

/**
 * 获取自有车辆详情
 */
export function getSelfCar (data) {
	return get('/common/getVehicleInfoById', Object.assign({
		id: null
	}, data))
}

/**
 * 绑定自有车辆GPS
 */
export function bindSelfCarGps (data) {
	return post('/common/bindVehicleGps', Object.assign({
		SNNum: null,
		vehicleId: null,
		vehicleNum: null
	}, data))
}


/**
 * 加载车辆品牌选项数据
*/
export function loadCarBrandOptions () {
  return Promise.resolve([{
    text: '三一',
    value: '三一'
  }, {
    text: '中联',
    value: '中联'
  }, {
    text: '徐工',
    value: '徐工'
  }, {
    text: '其他',
    value: '其他'
  }])
}

/**
 * 加载地盘品牌选项数据
*/
export function loadCarChassisBrandOptions () {
  return Promise.resolve([{
    text: '奔驰',
    value: '奔驰'
  }, {
    text: '沃尔沃',
    value: '沃尔沃'
  }, {
    text: '斯堪尼亚',
    value: '斯堪尼亚'
  }, {
    text: '汕德卡',
    value: '汕德卡'
  }, {
    text: '三一',
    value: '三一'
  }, {
    text: '东风',
    value: '东风'
  }, {
    text: '解放',
    value: '解放'
  }, {
    text: '其他',
    value: '其他'
  }])
}

/**
 * 加载桥树选项数据
*/
export function loadCarAxisOptions () {
  return Promise.resolve([{
    text: '2',
    value: '2'
  }, {
    text: '3',
    value: '3'
  }, {
    text: '4',
    value: '4'
  }, {
    text: '5',
    value: '5'
  }, {
    text: '其他',
    value: '其他'
  }])
}

/**
 * 加载节臂数选项数据
*/
export function loadCarArmSegmentOptions () {
  return Promise.resolve([{
    text: '0',
    value: '0'
  }, {
    text: '1',
    value: '1'
  }, {
    text: '2',
    value: '2'
  }, {
    text: '3',
    value: '3'
  }, {
    text: '4',
    value: '4'
  }, {
    text: '5',
    value: '5'
  }, {
    text: '6',
    value: '6'
  }, {
    text: '7',
    value: '7'
  }, {
    text: '其他',
    value: '其他'
  }])
}

/**
 * 加载司机数据
 */
export function loadDriverData (data) {
	return post(`/common/queryAllDriverInfo?queryParam=${data.queryParam?data.queryParam:''}`)
}

/**
 * 向车里增加司机
 */
export function addCarDriver (data) {
	return post(`/common/addVehicleDrivers?newIds=${data.newIds}&vehicleId=${data.vehicleId}`)
}

/**
 * 
 */
export function replaceDriver (data) {
	return post(`/common/replaceVehicleDriver`,data)
}

/**
 * 获取泵车坐标
 */
export function getCarLocation (data) {
	return post('/common/getVehicleLocationByParam', Object.assign({
		vehicleId: null
	}, data))
}

/**
 * 获取车辆管理列表
 */
export function getAllVehicleList (data) {
	return get(`/common/getAllVehicleList?vehicleType=${data.isCar}&queryParam=${data.queryParam}`)
}